<template>
  <van-action-bar>
    <van-action-bar-icon icon="chat-o" text="客服" dot />
    <van-action-bar-icon icon="cart-o" text="购物车" :badge="numdata" />
    <van-action-bar-icon icon="shop-o" text="店铺" dot />
    <van-action-bar-button
      type="warning"
      text="加入购物车"
      @click="onClickIcon"
    />
  </van-action-bar>
</template>

<script>
import { showSuccessToast } from "vant";
export default {
  data() {
    return {
      numdata: "1",
      goodsid: "",
    };
  },
  props: ["num", "goodslistid"],
  watch: {
    num: {
      handler: function (newval) {
        // console.log(newval);
        this.numdata = newval;
      },
      deep: true,
    },
    goodslistid: {
      handler: function (newval) {
        // console.log(newval);
        this.goodsid = newval;
      },
      deep: true,
    },
  },
  methods: {
    onClickIcon() {
      if (localStorage.getItem("userid")) {
        this.$http({
          url: "/cart/add",
          method: "post",
          data: {
            // userid   proid  num
            userid: localStorage.getItem("userid"),
            proid: this.goodsid,
            num: this.numdata,
          },
        }).then((res) => {
          if (res.data.code === "200") {
            showSuccessToast("加入购物车成功");
            this.$router.push("/shoppingcart");
          }
        });
      }else{
        this.$router.push('/Login')
      }
    },
    created() {

    },
  },
};
</script>

<style>
</style>